<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>日账单查询</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="{{asset('/layuiadmin/layui/css/layui.css')}}" media="all">
    <link rel="stylesheet" href="{{asset('/layuiadmin/style/admin.css')}}" media="all">
    <style>
      .yname {
        font-size: 13px;
        color: #444;
      }

      .bj {
        width: 45px;
        height: 45px;
      }

      .logo {
        width: 45px;
        height: 45px;
      }
    </style>
  </head>
  <body>
    <div class="layui-fluid">
      <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
          <div class="layui-card"style="margin-top:50px">
            <div class="layui-card-header">对账单</div>
            <div class="layui-card-body">
              <form class="layui-form layui-form-pane">
                <div class="layui-form-item">
                  <!--div class="layui-inline">
                    <label class="layui-form-label">查询门店</label>
                    <div class="layui-input-inline">
                      <input type="text" class="layui-input" id="searchShop" >
                    </div>
                  </div-->
                  <div class="layui-inline">
                    <label class="layui-form-label">对账单类型</label>
                    <div class="layui-input-inline">
                      <select name="type">
                        <option value=""></option>
                        <option value="daily">按日</option>
                        <option value="monthly">按月</option>
                      </select>
                    </div>
                  </div>
                  <div class="layui-inline">
                    <label class="layui-form-label">查询时间</label>
                    <div class="layui-input-inline" style="width: 300px">
                      <input name="date" type="text" class="layui-input" id="searchDate" >
                    </div>
                  </div>
                  <div class="layui-inline">
                    <div class="layui-input-inline">
                      <button class="layui-btn" lay-submit="" lay-filter="search">搜索</button>
                      <button class="layui-btn" lay-submit="" lay-filter="export">导出</button>
                    </div>
                  </div>
                </div>
              </form>
              <table id="bill" ></table>
            </div>
          </div>
        </div>
      </div>
    </div>


  </body>
  <script type="text/javascript" src="{{asset('/layuiadmin/layui/layui.js')}}"></script>
  <script type="text/javascript" >
    layui.use(['laydate','table'], function () {
      let token = localStorage.getItem("Publictoken");
      let $ = layui.$;
      let form = layui.form;
      let laydate = layui.laydate;
      let table = layui.table;

      laydate.render({
        elem: '#searchDate'
        ,type: 'datetime'
        ,range: ' 至 '
        ,format: 'yyyy-MM-dd HH:mm:ss'
        ,max:'{{date('Y-m-d H:i:s')}}'
      });

      table.render({
        elem: '#bill'
        , height: 500
        , method: 'post'
        , url: '/api/merchant/bill?token=' + token //数据接口
        , page: true //开启分页
        , cols: [[ //表头
          {field: 'bill_date', title: '账单时间', width: 200, fixed: 'left'},
          {field: 'shop_name', title: '门店名称'},
          {field: 'order_amount', title: '订单总额'},
          {field: 'receive_fee', title: '总手续费'},
          {field: 'refund_amount', title: '退款总额'},
          {field: 'receive_refund_fee', title: '退款总手续费', fixed: 'right'},
        ]]
      });

      form.on('submit(search)', function (data) {
        table.reload('bill', {
          page: {
            curr: 1 //重新从第 1 页开始
          },
          where: data.field
        });
        return false;
      });

      form.on('submit(export)', function (data) {
        let loading = layer.load(2);
        $.ajax({
          type: 'POST',
          url: '/api/merchant/billExport',
          data: {...data.field, token},
          dataType: 'json',
          success: function (res) {
            layer.close(loading);
            if (res.code == 0) {
              window.open(res.data.url, "_blank");
            } else {
              layer.msg(res.msg);
            }
          },
          error: function (res) {
            layer.close(loading);
            layer.msg('系统错误');
          },
        });
        return false;
      });

    });
  </script>
</html>